package com.qn.service.impl;

import com.qn.dao.FilterInfoDao;
import com.qn.entity.Industry;
import com.qn.entity.location.City;
import com.qn.entity.location.Provinces;
import com.qn.service.FilterInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <h1>过滤器信息服务</h1>
 *
 * @author olo
 * @className FilterInfoServiceImpl
 * @date 2021/10/19 11:26
 * Version 1.0
 */
@Service
public class FilterInfoServiceImpl implements FilterInfoService {
    @Resource
    FilterInfoDao filterInfoDao;

    @Override
    public void insertIndustryInfo(List<Industry> industries) {
        for (Industry industry : industries) {
            filterInfoDao.insertIndustryInfo(industry);
            filterInfoDao.insertIndustryInfoWithSub(industry.getSubIndustry(), industry.getId());
        }
    }

    @Override
    public List<Industry> getIndustryInfo() {
        return filterInfoDao.getIndustryInfo();
    }

    @Override
    public List<Provinces> getLocations() {
        return filterInfoDao.getLocationsInfo();
    }

    @Override
    public void insertLocations(List<Provinces> locations) {
        for (Provinces provinces : locations) {
            //遍历插入省份
            filterInfoDao.insertProvinces(provinces);
            for (City city : provinces.getCity()) {
                //遍历插入城市
                filterInfoDao.insertCity(city, provinces.getId());
                //插入地区
                filterInfoDao.insertRegion(city.getRegion(), city.getId());
            }
        }
    }
}